package com.sky.web.app;


import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
public class AppShoppingCartController {


    @Autowired
    private ShoppingCartService shoppingCartService;

    //加入购物车
    @PostMapping("/add")
    public Result save(@RequestBody ShoppingCart shoppingCart) {//1.接收参数
        //2.调用service查询
        shoppingCartService.save(shoppingCart);
        //3.返回结果
        return Result.success();
    }

    //查询购物车
    @GetMapping("/list")
    public Result findList() {
        List<ShoppingCart> list = shoppingCartService.findList();
        return Result.success(list);
    }

    //清空购物车
    @DeleteMapping("/clean")
    public Result clean() {
        shoppingCartService.clean();
        return Result.success();
    }

    //删减购物车中的一个商品(减号按钮)
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCart shoppingCart) {
        //1.调用service
        shoppingCartService.sub(shoppingCart);
        //2.返回结果
        return Result.success();
    }

}
